/***********************************************
 This file is part of redia-library-app-ios.
 
 Copyright (c) 2012, 2013 Redia A/S
 
 Redia-library-app-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-library-app-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-library-app-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */


#import "InfoGalleriXmlRpcClient201009.h"
#import "XMLRPCRequest.h"
#import "XMLRPCConnectionManager.h"
#import "XMLRPCResponse.h"
#import "NSString+LibUtils.h"


@implementation InfoGalleriXmlRpcClient201009

- (id)init 
{
	self = [super init];
	url = [NSURL URLWithString:REDIA_APP_INFOGALLERI_XMLRPC_URL];
	manager = [XMLRPCConnectionManager sharedManager];
	return self;
}

- (NSString*)addComment:(NSString*)customerId infoObjectId:(NSString *)infoObjectId authorName:(NSString *)authorName comment:(NSString *)comment authorEmail:(NSString *)authorEmail delegate:(id <XMLRPCConnectionDelegate>) d
{
	if ([infoObjectId isContaining:@"::"]) {
		NSArray* id_elements = [infoObjectId componentsSeparatedByString:@"::"];
		if (id_elements!=nil && [id_elements count]==2) {
			infoObjectId = [id_elements objectAtIndex:1];
		}
	}
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:infoObjectId];
	[params addObject:authorName];
	[params addObject:comment];
	[params addObject:authorEmail];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"addComment" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 

- (NSString*)notifyGalleryOwner: (NSString *)customerId galleryId:(NSString *)galleryId message:(NSString *)message delegate:(id <XMLRPCConnectionDelegate>) d
{	
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:galleryId];
	[params addObject:message];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"notifyGalleryOwner" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 
- (NSString*)addGalleryMetaData: (NSString *)customerId galleryId:(NSString *)galleryId key:(NSString *)key value:(NSString *)value delegate:(id <XMLRPCConnectionDelegate>) d
{
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:galleryId];
	[params addObject:key];
	[params addObject:value];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"addGalleryMetaData" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 
- (NSString*)addVote: (NSString *)customerId choiceId:(NSString *)choiceId delegate:(id <XMLRPCConnectionDelegate>) d
{
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:choiceId];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"addVote" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 
- (NSString*)getAllGalleries: (NSString *)customerId delegate:(id <XMLRPCConnectionDelegate>) d
{
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"getAllGalleries" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 
- (NSString*)getInfoObjectsByTags: (NSString *)customerId tags:(NSArray *)tags delegate:(id <XMLRPCConnectionDelegate>) d
{
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:tags];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"addComment" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 
- (NSString*)getGallerySkin: (NSString *)customerId galleryId:(NSString *)galleryId delegate:(id <XMLRPCConnectionDelegate>) d;
{

	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:galleryId];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"getGallerySkin" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 
- (NSString*)getGalleryChannels: (NSString *)customerId galleryId:(NSString *)galleryId delegate:(id <XMLRPCConnectionDelegate>) d
{
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:galleryId];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"getGalleryChannels" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 
- (NSString*)getChannelInfoObjects:(NSString *)customerId channelId:(NSString *)channelId  delegate:(id <XMLRPCConnectionDelegate>) d
{
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:channelId];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"getChannelInfoObjects" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 
- (NSString*)getInfoObject: (NSString *)customerId infoObjectId:(NSString *)infoObjectId delegate:(id <XMLRPCConnectionDelegate>) d
{
	NSMutableArray *params = [[NSMutableArray alloc] init];
	[params addObject:customerId];
	[params addObject:infoObjectId];
	XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: url];
	[request setMethod:@"getInfoObject" withParameters: params];
	NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
} 

-(NSString *)retryRequest:(XMLRPCRequest *)request delegate:(id<XMLRPCConnectionDelegate>)d
{
    NSString* newidentifier = [manager spawnConnectionWithXMLRPCRequest:request delegate:d];
    [self addRequestIdentifier:newidentifier forDelegate:d];
    return newidentifier;
}

@end
